package logger

import (
	"context"
	"sync"
)

var (
	mu sync.Mutex
	// 一开始初始化一个基础的，便于启动的时候记录日志，后续程序自定义的时候调用Init()方法可以修改
	log LoggerHelper = NewZapLog(NewOptions(), WithSugar(true))
)

func GetLogger() LoggerHelper {
	if log == nil {
		mu.Lock()
		log = NewZapLog(NewOptions(), WithSugar(true))
		mu.Unlock()
	}
	return log
}

func Init(opts *Options, zapOptions ...ZapLoggerOption) LoggerHelper {
	mu.Lock()
	// 默认使用sugar日志
	log = NewZapLog(opts, zapOptions...)
	mu.Unlock()
	return log
}

func Debug(msg string) {
	log.Debug(msg)
}
func DebugF(format string, v ...interface{}) {
	log.DebugF(format, v...)
}
func DebugContext(ctx context.Context, msg string) {
	log.DebugContext(ctx, msg)
}
func DebugContextF(ctx context.Context, format string, v ...interface{}) {
	log.DebugContextF(ctx, format, v...)
}
func Info(msg string) {
	log.Info(msg)
}
func InfoF(format string, v ...interface{}) {
	log.InfoF(format, v...)
}
func InfoContext(ctx context.Context, msg string) {
	log.InfoContext(ctx, msg)
}
func InfoContextF(ctx context.Context, format string, v ...interface{}) {
	log.InfoContextF(ctx, format, v...)
}
func Warn(msg string) {
	log.Warn(msg)
}
func WarnF(format string, v ...interface{}) {
	log.WarnF(format, v...)
}
func WarnContext(ctx context.Context, msg string) {
	log.WarnContext(ctx, msg)
}
func WarnContextF(ctx context.Context, format string, v ...interface{}) {
	log.WarnContextF(ctx, format, v...)
}
func Error(msg string) {
	log.Error(msg)
}
func ErrorF(format string, v ...interface{}) {
	log.ErrorF(format, v...)
}
func ErrorContext(ctx context.Context, msg string) {
	log.ErrorContext(ctx, msg)
}
func ErrorContextF(ctx context.Context, format string, v ...interface{}) {
	log.ErrorContextF(ctx, format, v...)
}
